package com.zwb.aiwebsite;

import com.zwb.aiwebsite.utils.ApplicationContextHolder;
import lombok.extern.slf4j.Slf4j;
import org.mybatis.spring.annotation.MapperScan;
import org.springframework.boot.SpringApplication;
import org.springframework.boot.autoconfigure.SpringBootApplication;
import org.springframework.boot.web.embedded.tomcat.TomcatServletWebServerFactory;
import org.springframework.context.ApplicationContext;
import org.springframework.data.jpa.repository.config.EnableJpaRepositories;

import java.net.InetAddress;
import java.net.UnknownHostException;

/**
 * 主启动类
 */
@Slf4j
@MapperScan("com.zwb.aiwebsite.mapper")
@EnableJpaRepositories
@SpringBootApplication
public class AiWebsiteApplication {

    public static void main(String[] args) {
        SpringApplication.run(AiWebsiteApplication.class, args);
        printInfo();

    }

    public static void printInfo(){
        try {
            ApplicationContext ctx = ApplicationContextHolder.getCtx();
            String ip = InetAddress.getLocalHost().getHostAddress();
            TomcatServletWebServerFactory tomcatServletWebServerFactory = (TomcatServletWebServerFactory) ctx
                    .getBean("tomcatServletWebServerFactory");
            int port = tomcatServletWebServerFactory.getPort();
            log.info("\n----------------------------------------------------------\n\t" +
                    "应用启动成功!Access URLs:\n\t" +
                    "Local访问网址: \t\thttp://localhost:" + port + "\n\t" +
                    "External访问网址: \thttp://" + ip + ":" + port + "\n\t" +
                    "swagger访问网址: \thttp://" + ip + ":" + port + "/swagger-ui.html\n" +
                    "----------------------------------------------------------");
        } catch (UnknownHostException e) {
            e.printStackTrace();
        }
    }

}
